package com.transcasafe.eanpay.core.config;

import com.transcasafe.eanpay.core.auth.Credential;
import com.transcasafe.eanpay.core.auth.EanPayCredential;
import com.transcasafe.eanpay.core.auth.EanPayValidator;
import com.transcasafe.eanpay.core.auth.Validator;
import com.transcasafe.eanpay.core.cipher.EanPayVerifier;
import com.transcasafe.eanpay.core.cipher.SHA256Signer;
import com.transcasafe.eanpay.core.cipher.Signer;
import lombok.Getter;

@Getter
public class EanPayConfig {

    private final String mchNo;
    private final String mchKey;

    public EanPayConfig(String mchNo, String mchKey) {
        this.mchNo = mchNo;
        this.mchKey = mchKey;
    }

    public static class Builder {
        private String mchNo;
        private String mchKey;

        public Builder mchNo(String mchNo) {
            this.mchNo = mchNo;
            return this;
        }

        public Builder mchKey(String mchKey) {
            this.mchKey = mchKey;
            return this;
        }

        public EanPayConfig build() {
            return new EanPayConfig(mchNo, mchKey);
        }
    }

    public Credential createCredential() {
        return new EanPayCredential(mchNo, createSigner());
    }

    public Validator createValidator() {
        return new EanPayValidator(new EanPayVerifier(createCredential()));
    }

    public Signer createSigner() {
        return new SHA256Signer(mchKey);
    }
}
